/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IUPrincipal.java
 *
 * Created on 23/07/2011, 20:04:10
 */

package interfaz;
import controladores.*;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.JTable;

/**
 *
 * @author Pablo
 */
public class IUPrincipal extends javax.swing.JFrame {

    IUEditorAntenas editor = new IUEditorAntenas();
    controladorIUPrincipal controlador= null;
    
    /** Creates new form IUPrincipal */
    public IUPrincipal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        numVariables = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        algoritmo = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        heuVariable = new javax.swing.JComboBox();
        heuValor = new javax.swing.JComboBox();
        editarAntenas = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        textFFrec = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Número de Variables");

        jLabel3.setText("SELECCIONE EL NÚMERO DE VARIABLES DEL PROBLEMA");

        numVariables.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opcion...", "4", "6", "8" }));

        jLabel2.setText("SELECCIONE EL ALGORITMO RESOLVENTE");

        jLabel4.setText("Algoritmo");

        algoritmo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opcion...", "ForwardChecking", "Arco Consistencia" }));

        jLabel5.setText("SELECCIONE LAS HEURÍSTICAS");

        jLabel6.setText("Heurística de variable");

        jLabel7.setText("Heurística de valor");

        heuVariable.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opcion...", "MVR", "Sin Heurística", " " }));

        heuValor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opcion...", "VMR", "Sin Heurística" }));

        editarAntenas.setText("Editar Antenas");
        editarAntenas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarAntenasActionPerformed(evt);
            }
        });

        jButton1.setText("RESOLVER");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel8.setText("Potencia máxima entre visibles :");

        textFFrec.setText("4");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel4)
                                            .addGap(18, 18, 18)
                                            .addComponent(algoritmo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jLabel5)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel6)
                                                .addComponent(jLabel7))
                                            .addGap(26, 26, 26)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(heuValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(heuVariable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jButton1)))))
                                .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE))
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 391, Short.MAX_VALUE)
                            .addGap(20, 20, 20))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(10, 10, 10)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addGap(18, 18, 18)
                                    .addComponent(numVariables, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(30, 30, 30)
                                    .addComponent(editarAntenas))
                                .addComponent(jLabel3)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(textFFrec, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)
                            .addContainerGap()))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(numVariables, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editarAntenas))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(textFFrec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(algoritmo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(heuVariable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(heuValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void editarAntenasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarAntenasActionPerformed
        // TODO add your handling code here:
        
        editor.setVisible(true);
        
    }//GEN-LAST:event_editarAntenasActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        boolean respuesta = false;
        if(algoritmo.getSelectedIndex() != 0 && heuValor.getSelectedIndex() != 0 && 
           heuVariable.getSelectedIndex() != 0 && numVariables.getSelectedIndex() != 0){
           controlador = new controladorIUPrincipal();
           respuesta = controlador.resolver(this);

            if (respuesta == true){
        IUResultado iuresultado = new IUResultado(controlador.getProblema(),controlador.getAlgoritmo());
        }else {
        sinSoluc sinsolucion = new sinSoluc();
            System.out.println("ES FALSO");
        sinsolucion.setVisible(true);
        }

       }else{
          MensajeError error =  new MensajeError("Debe seleccionar alguna combinación de Algoritmo - Heurística de Variable - Heurística de Valor");
//          int w=error.getMensaje().getWidth();
//          int h=error.getMensaje().getHeight();
//          error.setSize(w+10,h+10);
          error.setVisible(true);
       }
      
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new IUPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox algoritmo;
    private javax.swing.JButton editarAntenas;
    private javax.swing.JComboBox heuValor;
    private javax.swing.JComboBox heuVariable;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JComboBox numVariables;
    private javax.swing.JTextField textFFrec;
    // End of variables declaration//GEN-END:variables

    public double[] getFrecuenciasAntenas(){
        double[] frecuencias = new double [this.getNumVariables()];
       JTable tabla = editor.getAntenas();
       for (int i = 0 ; i<this.getNumVariables(); i++){
       frecuencias[i] = Double.parseDouble(tabla.getValueAt(i, 1).toString()); 
       }
       return frecuencias;
    }
    
    public double[] getPotenciasAntenas(){
        double [] potencias = new double [this.getNumVariables()];
        for (int i = 0 ; i<this.getNumVariables(); i++){
        potencias[i] = Double.parseDouble(editor.getAntenas().getValueAt(i, 2).toString());
        }
        return potencias;
    }
    
    public JComboBox getAlgoritmo() {
        return algoritmo;
    }

    public void setAlgoritmo(JComboBox algoritmo) {
        this.algoritmo = algoritmo;
    }

    public JComboBox getHeuValor() {
        return heuValor;
    }

    public void setHeuValor(JComboBox heuValor) {
        this.heuValor = heuValor;
    }

    public JComboBox getHeuVariable() {
        return heuVariable;
    }

    public void setHeuVariable(JComboBox heuVariable) {
        this.heuVariable = heuVariable;
    }

    public int getNumVariables() {
        return Integer.parseInt(numVariables.getSelectedItem().toString());
    }

    public void setNumVariables(JComboBox numVariables) {
        this.numVariables = numVariables;
    }

    public double getFrecuencia() {
        return Double.parseDouble(this.textFFrec.getText());
    }
}
